#!/bin/bash
if [ $# -ne 1  ]
then
    echo "Usage: x60cmFOneSingleField.sh prefix"
    echo "prefix is the first 14 character of the fits name, like M151016_C00027 "
    exit 0
fi
dir_now=`pwd`

stringtimeForMonitorT=`date -u +%Y%m%d`
dir_reduction=$HOME/workspace/reduction/$stringtimeForMonitorT
cd $dir_reduction
rm combinelist
cd $dir_now

fitnameprefix=$1
#ra=$2
#dec=$3
fitfilelist=`echo $fitnameprefix | awk '{print($1"*.fit")}'`
comfit=`echo $fitnameprefix | awk '{print($1"_com.fit")}'`
rdnoise=7.0
gain=1.5

xcombineimage (  )
{
    cd $HOME/iraf
    cp -f login.cl.old login.cl
    echo noao >> login.cl
    echo digiphot >> login.cl
    echo daophot >>login.cl
    echo "cd $dir_reduction" >> login.cl
    echo flpr >> login.cl
    echo "imcombine(\"@combinelist\",\"$comfit\", reject=\"crreject\",combine=\"median\",scale=\"exposure\",weight=\"exposure\",rdnoise=$rdnoise,gain=$gain)"         >>login.cl
    echo logout >>login.cl
    cl < login.cl >xlogfile
    cd $dir_reduction
    echo "=============="$comimage" finished====================="
}  




ls $fitfilelist >list
for Fitfile in `cat list`
do
    echo $Fitfile
    x60cmFandCom.sh $Fitfile
done
xcombineimage


